package cn.com.code.hwjs;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 名字的漂亮度
 *
 * @author zhengpei
 * https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3?tpId=37&tqId=21268&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=undefined&tags=&title=
 * @date 2022/5/1
 */
public class Hwjs45 {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (sc.hasNext()) {
      int N = sc.nextInt();
      for (int i = 0; i < N; i++) {
        String str = sc.next();
        System.out.println(getScore(str));
      }
    }
  }

  private static int getScore(String str) {
    char[] chars = str.toCharArray();
    int[] count = new int[26];

    // 转换为小写，对应位置字符出现的次数统计
    for (int i = 0; i < chars.length; i++) {
      Character.toLowerCase(chars[i]);
      count[chars[i] - 'a']++;
    }

    //升序
    Arrays.sort(count);

    int score = 0;
    for (int i = 1; i <= 26; i++) {
      score = score + i * count[i - 1];
    }
    return score;
  }

}
